package loginFlash
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.ByteArray;
	
	import mx.core.ByteArrayAsset;
	
	public class RandomName extends Sprite
	{
		[Embed(source="assets/姓名大全.txt", mimeType="application/octet-stream")]
		private static const embedNameBanned:Class;
		
		private var firstName:Array,lastName:Array;
		private var playerName:TextField;
		
		public function RandomName()
		{
			super();
			init();
			this.stage.addEventListener(MouseEvent.CLICK,randName);
		}
		
		public function randName(evt:MouseEvent=null):void {
			playerName.text = genName();
		}
		
		public function genName():String {
			var name:String="";
			
			var i:Number = Math.random()*100;
			
			if(i<100) {
				name = firstName[int(Math.random()*firstName.length)];
			}else {
				name = firstName[int(Math.random()*firstName.length/10)];
			}
			
			if(i<10) {
				name += lastName[int(Math.random()*lastName.length)];
			}else {
				name += lastName[int(Math.random()*lastName.length)]+lastName[int(Math.random()*lastName.length)];
			}
			return name;
		}
		
		public function init():void {
			playerName = new TextField();
			playerName.x = 100;playerName.y = 100;
			playerName.mouseEnabled = false;
			this.addChild(playerName);
			
			var storyByteArray:ByteArrayAsset = ByteArrayAsset(new embedNameBanned());
			var banWorld:String = storyByteArray.readUTFBytes(storyByteArray.length);
			var arr:Array = banWorld.split("\r\n");
			firstName= arr[0].split(",");
			lastName = arr[1].split(",");
			randName();
		}
	}
}